package Service

import (
	"context"
	"google.golang.org/grpc"
	"selfService/tool"
	service "selfService/好友相关/service"
)

type FrineService struct {

}


var friendAddr = tool.GetConf().FriendAddr

//     rpc get_friends(get_friends_request) returns (get_friends_response);
//// 根据id获得好友id列表
func (this *FrineService) Get_friends(Userid string)(*service.GetFriendsResponse, error) {
	coon,err := grpc.Dial(friendAddr,grpc.WithInsecure())
	if err!=nil {
		return nil,err
	}
	InterestClient := service.NewInterestServiceClient(coon)
	result,err := InterestClient.GetFriends(context.Background(),&service.GetFriendsRequest{
		UserId: Userid,
	})
	if err!=nil {
		return nil,err
	}
	return result,nil
}

//     rpc get_apply(get_apply_request) returns (get_apply_response);          // 根据id获得申请人id列表
//// 根据id获得申请人id列表
func (this *FrineService) Get_apply(Userid string)(*service.GetApplyResponse, error) {
	coon,err := grpc.Dial(friendAddr,grpc.WithInsecure())
	if err!=nil {
		return nil,err
	}
	InterestClient := service.NewInterestServiceClient(coon)
	result,err := InterestClient.GetApply(context.Background(),&service.GetApplyRequest{
		UserId: Userid,
	})
	if err!=nil {
		return nil,err
	}
	return result,nil
}

//    rpc agree_apply(agree_apply_request) returns (agree_apply_response);    // 根据id同意申请     // 根据id获得申请人id列表
//    根据id同意申请
func (this *FrineService) Agree_apply(Userid1 string,Userid2 string)(*service.AgreeApplyResponse, error) {
	coon,err := grpc.Dial(friendAddr,grpc.WithInsecure())
	if err!=nil {
		return nil,err
	}
	InterestClient := service.NewInterestServiceClient(coon)
	result,err := InterestClient.AgreeApply(context.Background(),&service.AgreeApplyRequest{
		UserId1: Userid1,
		UserId2: Userid2,
	})
	if err!=nil {
		return nil,err
	}
	return result,nil
}

//     rpc refuse_apply(refuse_apply_request) returns (refuse_apply_response); // 根据id拒绝申请
//   // 根据id拒绝申请
func (this *FrineService) Refuse_apply(Userid1 string,Userid2 string)(*service.RefuseApplyResponse, error) {
	coon,err := grpc.Dial(friendAddr,grpc.WithInsecure())
	if err!=nil {
		return nil,err
	}
	InterestClient := service.NewInterestServiceClient(coon)
	result,err := InterestClient.RefuseApply(context.Background(),&service.RefuseApplyRequest{
		UserId1: Userid1,
		UserId2: Userid2,
	})
	if err!=nil {
		return nil,err
	}
	return result,nil
}

//     rpc create_apply(create_apply_request) returns (create_apply_response); // 传⼊id1和2进⾏好友添加
//      // 传⼊id1和2进⾏好友添加
func (this *FrineService) Create_apply(Userid1 string,Userid2 string)(*service.CreateApplyResponse, error) {
	coon,err := grpc.Dial(friendAddr,grpc.WithInsecure())
	if err!=nil {
		return nil,err
	}
	InterestClient := service.NewInterestServiceClient(coon)
	result,err := InterestClient.CreateApply(context.Background(),&service.CreateApplyRequest{
		UserId1: Userid1,
		UserId2: Userid2,
	})
	if err!=nil {
		return nil,err
	}
	return result,nil
}

//      rpc delete_friend(deleteFriend_requese) returns(deleteFriend_response); // 传入id 删除两个好友关系
//     / 传入id 删除两个好友关系
func (this *FrineService) Delete_friend(hostId string, friendId string)(*service.DeleteFriendResponse, error) {
	coon,err := grpc.Dial(friendAddr,grpc.WithInsecure())
	if err!=nil {
		return nil,err
	}
	InterestClient := service.NewInterestServiceClient(coon)
	result,err := InterestClient.DeleteFriend(context.Background(),&service.DeleteFriendRequese{
		HostId: hostId,
		FriendId: friendId,
	})
	if err!=nil {
		return nil,err
	}
	return result,nil
}

